package com.byzk.p2p.admin.system.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.system.dao.GoodDao;
import com.byzk.p2p.admin.system.dto.Good;
import com.byzk.p2p.admin.system.vo.GoodVo;

@Service
public class GoodService {
	
	@Autowired
	private GoodDao goodDao ; 
	
	/**
	 * 查询所有商品列表
	 * @param index
	 * @param limit
	 * @return
	 */
	public PageInfo<GoodVo> listGood(GoodVo info){
		int count=goodDao.count(info);
		List<GoodVo> voList= goodDao.list(info);
		PageInfo<GoodVo> page=new PageInfo<GoodVo>(count, info.getIndex() , info.getLimit());
		page.setPageList(voList);
		return page;
	}
	
	/**
	 *通过商品id查询商品
	 */
	public GoodVo detail(Integer id){
		return goodDao.selectById(id);
	}
	
	public Integer saveOrUpdate1(GoodVo goodVo){
		if(goodVo.getId() == null){
			return goodDao.insert1(goodVo) ; 
		}else{
			return goodDao.update1(goodVo);
		}
	}
	
	public Integer saveOrUpdate(Good good){
		if(good.getId() == null){
			return goodDao.insert(good) ; 
		}else{
			return goodDao.update(good);
		}
	}
	

	
	
	public Integer delete(Integer id){
		return goodDao.delete(id);
	}
	
	public List<Good> list(){
		return goodDao.goodList();
	}

}
